﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
    public partial class CompanyPaymentForm : Form
    {
        private String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=NauferTransactionDemoDB.accdb";
        public CompanyPaymentForm()
        {
            InitializeComponent();
        }



















        public void comboboxload()
        {

            OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
            oleDbConnection1.Open();
            OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("Select jobpk,jobcode from  jobcodemastertable", oleDbConnection1);
            OleDbDataReader reader = oleDbCommand1.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Columns.Add("jobpk", typeof(int));
            dt.Columns.Add("jobcode", typeof(string));
            dt.Load(reader);
            cmbjobcode.ValueMember = "jobpk";
            cmbjobcode.DisplayMember = "jobcode";
            cmbjobcode.DataSource = dt.DefaultView;

            oleDbConnection1.Close();

        }


        public void comboQuotationboxload()
        {

            OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
            oleDbConnection1.Open();

            OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("Select quotationpk ,quotationcode , amount from  quotationmastertable  where jobpk = " + cmbjobcode.SelectedValue + " AND isconfirmed ='T' ", oleDbConnection1);



            OleDbDataReader reader = oleDbCommand1.ExecuteReader();


            DataTable dt = new DataTable();

            dt.Columns.Add("quotationpk", typeof(int));
            dt.Columns.Add("quotationcode", typeof(string));
            dt.Columns.Add("amount", typeof(int));
            dt.Load(reader);
            if (dt.Rows.Count != 0)
            {
            cmbQuotationcode.ValueMember = "quotationpk";
            cmbQuotationcode.DisplayMember = "quotationcode";
            cmbQuotationcode.DataSource = dt.DefaultView;
               // txtamount.Text = dt.Rows[0]["amount"].ToString();



                oleDbConnection1.Close();
            }
            else
            {
                MessageBox.Show("NO QUOTATION OF SAME");
                cmbQuotationcode.Text = "";
                
            }

        }

        private void CompanyPaymentForm_Load(object sender, EventArgs e)
        {
            comboboxload();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmbjobcode_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboQuotationboxload();
        }

        private void rbtCash_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtcheque.Checked)
            {
                txtBankName.Enabled = true;
                txtchequeno.Enabled = true;
                dtpchequedate.Enabled = true;
                dtpreleasingdate.Enabled = true;

            }
            else
            {
                txtBankName.Enabled = false;
                txtchequeno.Enabled = false;
                dtpchequedate.Enabled = false;
                dtpreleasingdate.Enabled = false;
            }
        }



        /// <summary>
        /// VALIDATES ALL CONTROL
        /// </summary>
        /// <returns></returns>
        public Boolean validationcontrol()
        {
            Boolean sucess = true;
          
          
            
             if (mxtAmount.Text.Trim() == null || mxtAmount.Text.Trim() == "")
            {

                mxtAmount.Focus();
                mxtAmount.Text = "";
                sucess = false;
                lblstatus.Text = "Enter Acceptor Name";
            }
            else if (rbtcheque.Checked)
            {
                if (txtchequeno.Text.Trim() == null || txtchequeno.Text.Trim() == "")
                {

                    txtchequeno.Focus();
                    txtchequeno.Text = "";
                    sucess = false;
                    lblstatus.Text = "Enter Cheque No";
                }
                if (txtBankName.Text.Trim() == null || txtBankName.Text.Trim() == "")
                {

                    txtBankName.Focus();
                    txtBankName.Text = "";
                    sucess = false;
                    lblstatus.Text = "Enter Bank Name";
                }


            }




            return sucess;
        }












    }
}
